<template>
    <div class="mod-config">
      <el-form :inline="true" :model="dataForm" >
        <el-form-item>
          <el-input v-model="dataForm.name" placeholder="商家姓名" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.account" placeholder="商家账号" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.contactPhoneNumber" placeholder="手机号码" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.status" placeholder="请选择类型">
            <el-option v-for="item in optionTwo" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">查询</el-button>
          <el-button type="primary" @click="resetting()">重置</el-button>
          <!-- <el-button v-if="isAuth('course:coursetype:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button> -->
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="addOrUpdateHandle()" v-if="isAuth('sys:user:add')">开户</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="dataList" border v-loading="dataListLoading" @selection-change="selectionChangeHandle"
        style="width: 100%">
        <el-table-column type="selection" header-align="center" align="center" width="50">
        </el-table-column>
        <el-table-column  prop="account"  header-align="center" align="center" label="账号"></el-table-column>
        <el-table-column prop="createTime" header-align="center" align="center" label="开户时间">
          <template slot-scope="scope">
            <span>{{ scope.row.createTime?getStrTime(scope.row.createTime):"" }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="name" header-align="center" align="center" label="商家名称"></el-table-column>
        <el-table-column prop="contactPhoneNumber" header-align="center" align="center" label="手机号码"></el-table-column>
        <el-table-column prop="balance" header-align="center" align="center" label="钱包余额"></el-table-column>
        <el-table-column prop="status" header-align="center" align="center" label="状态">
          <template slot-scope="scope">
            <span>{{scope.row.status==0?'冻结':'正常'}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="checkTime" header-align="center" align="center" label="冻结时间">
          <template slot-scope="scope">
            <span>{{scope.row.checkTime?getStrTime(scope.row.checkTime):''}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="checkName" header-align="center" align="center" label="冻结操作人"></el-table-column>
        <el-table-column prop="remark" header-align="center" align="center" label="备注"></el-table-column>
        <el-table-column fixed="right" header-align="center" align="center" width="200" label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="uStatus(scope.row.id, 0)" v-if="scope.row.status == 1 && isAuth('sys:user:disable')">冰洁</el-button>
            <el-button type="text" size="small" @click="uStatus(scope.row.id, 1)" v-if="scope.row.status == 0 && isAuth('sys:user:enable')">解冻</el-button>
            <el-button v-if="isAuth('sys:user:password:update')" type="text" size="small" @click="wallet(scope.row.id)">明细</el-button>
            <el-button type="text" size="small" v-if="isAuth('sys:user:delete')" @click="uStatus(scope.row.id, 3)">调额</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <el-dialog :title="statusType==3?'调额':statusType==0?'钱包冻结':'钱包解冻'" :close-on-click-modal="false" :visible.sync="dialogVisible">
        <el-form
          :model="info"
          :rules="dataRule"
          ref="dataForm"
          label-width="80px"
        >
          <template v-if="statusType==3">
            <el-form-item label="调整金额：" prop="balance" label-width="150"> 
              <el-input type="number" style="width: 250px;" v-model="dataForm.balance" placeholder="请输入排序" oninput="value=value.replace(/[^0-9]/g,'')"></el-input>
            </el-form-item>
          </template>
          <template v-else>
            <el-form-item label="" prop="remark">
              <div>{{statusType==0?'冻结后只允许入帐，不可进行提现。':'解冻后只，钱包帐户可正常操作提现等功能。'}}</div>
              <el-input style="width: 300px;" v-model="dataForm.remark"  type="textarea" :rows="4" placeholder="请填写原因" ></el-input>
            </el-form-item>
          </template>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="dataFormSubmit()" >确定</el-button>
        </span>
      </el-dialog>
      <WalletDetails v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></WalletDetails>
    </div>
  </template>
  
  <script>
  import WalletDetails from './walletDetails'
  export default {
    components: {
      WalletDetails
    },
    data () {
      return {
        textarea:'',
        statusType:'',
        dialogVisible: false,
        ispasswordPop: false,
        dataForm: {
          id:'',
          key: '',
          status: null,
          name: ''
        },
        info: {},
        dataRule: {
            // platformCostPrice: [
            //   { required: true, message: '请输入平台售价', trigger: 'blur' }
            // ],
        },
        options: [
          {
            value: null,
            label: '全部'
          },
          {
            value: true,
            label: '1'
          },
          {
            value: false,
            label: '2'
          },
          {
            value: false,
            label: '3'
          }
        ],
        optionTwo: [
          {
            value: null,
            label: '全部'
          },
          {
            value: 1,
            label: '解冻'
          },
          {
            value: 0,
            label: '冻结'
          }
        ],
        addOrUpdateVisibles: false,
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    activated () {
      this.getDataList()
    },
    methods: {
      wallet(id){//钱包明细
        console.log(id);
        this.$router.push({ name: 'm-walletDetails', query: { id: id } })
      },
      uStatus(id,i) {
        this.dataForm.id=id
        this.statusType=i
        this.dialogVisible = true
      },
      dataFormSubmit(){
        if(this.statusType==3){
          this.modify()
        }else{
          this.disable()
        }
      },
      disable(){
        var url=this.statusType==0?'/admin/business/balance/disable':'/admin/business/balance/enable'
        this.$http({
          url: this.$http.adornUrl(url),
          method: 'post',
          data: this.$http.adornData({
            remark: this.dataForm.remark,
            id: this.dataForm.id
          })
        }).then(({ data }) => {
          if (data && data.code === '200') {
            this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.dataForm.remark=''
                  this.dialogVisible=false
                  this.getDataList()
                }
              })
          }
        })
      },
      modify(){
        this.$http({
          url: this.$http.adornUrl(`/admin/business/balance/modify`),
          method: 'post',
          data: this.$http.adornData({
            balance: this.dataForm.balance,
            id: this.dataForm.id
          })
        }).then(({ data }) => {
          if (data && data.code === '200') {
            this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.dialogVisible=false
                  this.getDataList()
                }
              })
          }
        })
      },
      resetting () {
        this.dataForm = {
          account: '',
          contactPhoneNumber: '',
          status: null,
          name: ''
        }
        this.getDataList()
      },
      // 获取数据列表
      getDataList () {
        this.$http({
          url: this.$http.adornUrl(`/admin/business/balance/page`),
          method: 'post',
          data: this.$http.adornData({
            pageNum: this.pageIndex,
            pageSize: this.pageSize,
            name: this.dataForm.name,
            account: this.dataForm.account,
            contactPhoneNumber: this.dataForm.contactPhoneNumber,
            status: this.dataForm.status
          })
        }).then(({ data }) => {
          if (data && data.code === '200') {
            this.dataList = data.list
            this.totalPage = data.total
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      }
    }
  }
  </script>
  